package com.xl.minyue.tc2.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xl.minyue.tc2.pojo.*;
import com.xl.minyue.tc2.service.ReportFormServiceImpl;
import com.xl.minyue.tc2.until.DingDing;
import com.xl.minyue.tc2.until.Emp;
import com.xl.minyue.tc2.until.ProTest;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
public class TestController {
    @Resource
    private ReportFormServiceImpl reportFormService;

    //免登
    @RequestMapping("/api/login.do")
    @ResponseBody
    public  HashMap<String, Object> login(HttpServletRequest req){
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            String data = IOUtils.toString(req.getInputStream());
            Map map = JSON.parseObject(data, Map.class);
            String authCode = map.get("authCode").toString();
            System.out.println(authCode+"-----authCode");
            String userId = DingDing.getUserIdByCode(authCode);
            Emp empDetail = DingDing.getEmpDetail(userId);
            if (empDetail.getUserName()!=null){
                resMap.put("data",empDetail);
                resMap.put("code","0");
                resMap.put("msg","请求成功");
            }
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"<----免登");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

//数据维护页面
    //根据主要分类和子分类查询点信息---数据维护页面显示数据列表-----pointinfo表格
    @RequestMapping("/api/showTagByKind.do")
    @ResponseBody
    public HashMap<String, Object> showTagByKind(HttpServletRequest req){
        System.out.println(new Date()+"<-------------开始时间");
        System.out.println(req.getRequestURL()+"<------showTagByKind--url");
        HashMap<String, Object> map = new HashMap<>();
        List<PointInfo> list = new ArrayList<>();
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            data=reader.readLine();
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            String kind2 = jsonObject.getString("kind2");
            String kind1 = jsonObject.getString("kind1");
            List<PointInfo> infoList = reportFormService.checkPointInfoByKind2(kind2, kind1);
            if(infoList.size()>0){
                for (PointInfo info:infoList) {
                    info.setKind1(kind1);
                    list.add(info);
                }
            }
            map.put("data",list);
            map.put("code","0");
            map.put("msg","请求成功");
        } catch (IOException e) {
            map.put("data","");
            map.put("code","1");
            map.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println("返回的结果:"+JSON.toJSONString(list)+"-----数据维护页面----");
        System.out.println(new Date()+"<-------------结束时间");
        return map;
    }

    //添加点
    @RequestMapping("/api/addPoints.do")
    @ResponseBody
    public HashMap<String, Object> addPoints2(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<---addPoints2--222----url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes(), "utf-8");
                data += line;
            }
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject reqMap = JSON.parseObject(data);
            String note = reqMap.getString("note");
            String name = reqMap.getString("name");
            String code = reqMap.getString("code");
            String kind_1 = reqMap.getString("kind1");
            String kind_2 = reqMap.getString("kind2");
            String unit = reqMap.getString("unit");
            String name2=name+"/"+unit;
            PointInfo p = new PointInfo();
            p.setPointcode(code);
            p.setPointname(name2);
            p.setComment(1);
            p.setKind1(kind_1);
            p.setKind2(kind_2);
            p.setUnit(unit);
            p.setNote(note);
            System.out.println(p.toString()+"<--------p");
            Boolean b = reportFormService.addPoints(p);
            String msg="添加点失败";
            if (b){
                msg="添加点成功";
            }
            resMap.put("data",msg);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"-----添加点-----");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

    //删除点
    @RequestMapping("/api/delePoints.do")
    @ResponseBody
    public  HashMap<String, Object> delePoints(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<---delePoints------url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        String msg="删除失败";
        try {
            String data = IOUtils.toString(req.getInputStream());
            JSONObject map = JSON.parseObject(data);
            String id = map.getString("id");
            Boolean dele = reportFormService.delePoints(id);
            if (dele){
                msg="删除成功";
            }
            resMap.put("code","0");
            resMap.put("data",msg);
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(msg+"-----msg----------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

//实时分类---------部分
    //接收实时数据并保存
    //没有做实时数据的重复添加的判断<-----------------------问题
    @RequestMapping("/api/addDataFromPI.do")
    @ResponseBody
    public  HashMap<String, Object> receiveDataFromPI(HttpServletRequest request){
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        boolean f=false;
        String data2=null;
        String data = request.getParameter("data");
        if(data==null||data.equals("")){
            System.out.println("获取请求头中传递的数据data!!!!!1");
            // 得到请求头的name集合
            Enumeration<String> em = request.getHeaderNames();
            while (em.hasMoreElements()) {
                String name =em.nextElement();
                //System.out.println("11111111111111111111111");
                if(name.equals("data")){
                    data2 = request.getHeader(name);
                }
            }
        }else{
            data2=data;
        }
        System.out.println(data2+"<---------接收的数据data2");
        JSONObject jsonObject = JSON.parseObject(data2);
        JSONArray dataArr = jsonObject.getJSONArray("data");
        System.out.println(dataArr+"<-----------dataArr");
        boolean b=false;
        if(dataArr.size()>0){
                b = reportFormService.updateStatus();
                System.out.println(b+"<-------------b");
                for (int j = 0; j < dataArr.size(); j++) {
                    String s = dataArr.get(j).toString();
                    JSONObject map = JSON.parseObject(s);
                    String tagCode = map.getString("tagCode");
                    String tagValue = map.getString("tagValue");
                    String time = map.getString("getTime");
                    String tagName = reportFormService.getPointNameToTagName2(tagCode);
                    Date date=null;
                    try {
                        date= d2.parse(time);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    String date2=dateFormat2.format(date);
                    System.out.println(date2+"<------------date2,----->"+tagCode);
                    //保存数据
                    TagInfo tagInfo = new TagInfo();
                    tagInfo.setTagname(tagCode);
                    tagInfo.setColltime(time);
                    tagInfo.setComment(1);
                    tagInfo.setDatetime(date2);
                    tagInfo.setTagvalue(tagValue);
                    tagInfo.setTagname2(tagName);
                    tagInfo.setStatus("new");
                    System.out.println(tagInfo.toString()+"<----------tagInfo"+b);
                    if (b){
                        f=reportFormService.addData(tagInfo);
                        if(f){
                            System.out.println("添加成功!!!<---"+tagName+"和"+tagCode);
                        }else{
                            System.out.println("添加失败!!!<---"+tagName+"和"+tagCode);
                        }
                    }
                }
        }else{
            List<TagInfo> tagInfoList = reportFormService.getNewData();
            b = reportFormService.updateStatus();
            String coll = d2.format(new Date());
            String today = dateFormat2.format(new Date());
            for (TagInfo p:tagInfoList) {
                if(b){
                    //保存数据
                    TagInfo tagInfo = new TagInfo();
                    tagInfo.setTagname(p.getTagname());
                    tagInfo.setColltime(coll);
                    tagInfo.setComment(1);
                    tagInfo.setDatetime(today);
                    tagInfo.setTagvalue("0.00");
                    tagInfo.setTagname2(p.getTagname2());
                    tagInfo.setStatus("new");
                   boolean f2=reportFormService.addData(tagInfo);
                    if(f2){
                        System.out.println("添加成功!!!<---"+p.getTagname2()+"和"+p.getTagname());
                    }else{
                        System.out.println("添加失败!!!<---"+p.getTagname2()+"和"+p.getTagname());
                    }
                }
            }
        }
        if(f){
            resMap.put("data","接收到数据");
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        }else{
            resMap.put("data","传输数据为空");
            resMap.put("code","1");
            resMap.put("msg","请求成功");
        }
        System.out.println("接口返回的json:"+JSON.toJSONString(resMap));
        return resMap;
    }

    //展示该分类下指标的最新数据列表-------------实时分类下的指标
    @RequestMapping("/api/showTagNewDataByKind.do")
    @ResponseBody
    public HashMap<String, Object> showTagNewDataByKind(HttpServletRequest req){
        System.out.println(new Date()+"<-------------开始时间");
        System.out.println(req.getRequestURL()+"<----showTagNewDataByKind----url");
        HashMap<String, Object> resMap = new HashMap<>();
        List<TagInfo> list=new ArrayList<>();
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            data=reader.readLine();
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            String kind1 = jsonObject.getString("kind1");
            String kind2 = jsonObject.getString("kind2");
            kind1="实时";
            System.out.println(kind1+"<----kind1----kind2--->"+kind2);
            List<TagInfo> list2 = reportFormService.showTagNewDataByKind_2(kind1, kind2);
            for (TagInfo t:list2) {
                if(t!=null){
                    t.setTagvalue(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                    list.add(t);
                }

            }
            resMap.put("data",list);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (IOException e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"----------实时最新数据-------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }



    @RequestMapping("/api/showData.do")
    @ResponseBody
    public HashMap<String, Object> showReportData(HttpServletRequest req){
        System.out.println(new Date()+"<-------------开始时间");
        System.out.println(req.getRequestURL()+"<--------showReportData------url");
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat d1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat d3 = new SimpleDateFormat("mm");
        SimpleDateFormat d4 = new SimpleDateFormat("HH");
        SimpleDateFormat d5 = new SimpleDateFormat("HH:mm");
        String format = d1.format(new Date());
        List<String> nowTimeList =ProTest.getShowArray();
        //System.out.println(JSON.toJSONString(nowTimeList)+"<------------");
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes());
                data += line;
            }
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray jsonArray = jsonObject.getJSONArray("codeList");
            String date = jsonObject.getString("date");
           if (date==null || date.equals("")){
               date=format;
           }
            System.out.println(date+"<--------展示数据的日期"+jsonArray);
            List<Object> list = new ArrayList<>();
            if (jsonArray.size()>0){
                for (int i = 0; i <jsonArray.size() ; i++) {
                    String code = jsonArray.get(i).toString();
                    String name=null;
                   int num_5 = code.indexOf("?&=");
                   if(num_5 !=-1){
                       name=code.substring(num_5+"?&=".length(),code.length());
                       code=code.substring(0,num_5);
                   }
                    Map map2 = new HashMap<>();
                    List<String> list2 = new ArrayList<>();
                    List<TagInfo> infoList = reportFormService.showDataByDateAndPoint2_(code, date);
                    //System.out.println(JSON.toJSONString(infoList)+"<-------"+name);
                    /*for (int j = 0; j <infoList.size(); j++) {
                        TagInfo t = infoList.get(j);
                        if (name==null){
                            name=t.getTagname2();
                        }
                        String colltime = t.getColltime();
                        Date parse = d2.parse(colltime);
                        if(j==0||j==1||j==(infoList.size()-1)){
                            System.out.println(t.toString()+"<--------"+j);
                        }
                        if(j==0){
                            int minitue = Integer.parseInt(d3.format(parse));
                            int hour= Integer.parseInt(d4.format(parse));
                            int floor = (int) Math.floor(minitue / 5);
                            int num5=hour*12+floor;
                            for (int k = 0; k < num5; k++) {
                                list2.add("0.00");
                            }
                        }
                        long num = new Date().getTime() - parse.getTime();
                        if (num>0){
                            list2.add(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                        }
                    }*/
                    int a=0;
                    int b=0;
                    for (int j = 0; j <infoList.size(); j++) {
                        TagInfo t = infoList.get(j);
                        String colltime = t.getColltime();
                        Date parse = d2.parse(colltime);
                        //System.out.println(JSON.toJSONString(list2+"<----------list2,>>>>>"+j));
                        String hour_minitue = d5.format(parse);
                        //System.out.println(hour_minitue+"<----------"+j);
                        for (int k = b; k < nowTimeList.size(); k++) {
                            if (nowTimeList.get(k).equals(hour_minitue)){
                                a=k;
                                break;
                            }
                        }
                        //System.out.println(a+"a_a_a_a_a"+b+"_a_a_a_a_"+j);
                        //System.out.println(nowTimeList.get(a)+"<-----time");
                        for (int k2 = b; k2 < a; k2++) {
                            list2.add("0.00");
                            if (k2==(a-1)){
                                b=k2;
                                b++;
                            }
                        }
                        //System.out.println(b+"bbbbbbbbbbb-->"+j);
                        long num = new Date().getTime() - parse.getTime();
                        if (num>0){
                            list2.add(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                            b++;
                        }

                    }
                    if(name==null){
                        map2.put("tagName","");
                    }else{
                        map2.put("tagName",name);
                    }
                    map2.put("tagCode",code);
                    map2.put("tagVlue",list2);
                    list.add(map2);
                    System.out.println(list2.size()+"<-----changdu");
                }
            }

            resMap.put("data",list);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"---------实时数据曲线------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

    //展示曲线数据页面-------实时数据-----------数据展示到当前时间
    @RequestMapping("/api/showData2.do")
    @ResponseBody
    public HashMap<String, Object> showReportData2(HttpServletRequest req){
        System.out.println(new Date()+"<-------------开始时间");
        System.out.println(req.getRequestURL()+"<--------showReportData2------url");
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat d1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat d5 = new SimpleDateFormat("HH:mm");
        String format = d1.format(new Date());
        List<String> nowTimeList = ProTest.getShowArray();
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes());
                data += line;
            }
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray jsonArray = jsonObject.getJSONArray("codeList");
            String date = jsonObject.getString("date");
            if (date==null || date.equals("")){
                date=format;
            }
            System.out.println(date+"<--------展示数据的日期"+jsonArray);
            List<Object> list = new ArrayList<>();
            if (jsonArray.size()>0) {
                for (int i = 0; i < jsonArray.size(); i++) {
                    String code = jsonArray.get(i).toString();
                    String name = null;
                    int num_5 = code.indexOf("?&=");
                    if (num_5 != -1) {
                        name = code.substring(num_5 + "?&=".length(), code.length());
                        code = code.substring(0, num_5);
                    }
                    Map map2 = new HashMap<>();
                    List<String> list2 = new ArrayList<>();
                    List<TagInfo> infoList = reportFormService.showDataByDateAndPoint2_(code, date);
                    int a=0;
                    int b=0;
                    for (int j = 0; j <infoList.size(); j++) {
                        TagInfo t = infoList.get(j);
                        Date parse = d2.parse(t.getColltime());
                        String hour_minitue = d5.format(parse);
                        for (int k = b; k < nowTimeList.size(); k++) {
                            if (nowTimeList.get(k).equals(hour_minitue)){
                                a=k;
                                break;
                            }
                        }
                        for (int k2 = b; k2 < a; k2++) {
                            list2.add("0.00");
                            if (k2==(a-1)){
                                b=k2;
                                b++;
                            }
                        }
                        long num = new Date().getTime() - parse.getTime();
                        if (num>0){
                            list2.add(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                            b++;
                        }
                    }
                    if (name == null) {
                        map2.put("tagName", "");
                    } else {
                        map2.put("tagName", name);
                    }
                    map2.put("tagCode", code);
                    map2.put("tagVlue", list2);
                    list.add(map2);
                }
            }
            resMap.put("data",list);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"---------实时数据曲线------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }



//日报
    //接收保存日报数据------------请求头传递数据--------数据保存到tagdatax3表格中
    @RequestMapping("/api/addDataFromX3ByDay.do")
    @ResponseBody
    public  HashMap<String, Object> receiveDataFromX3(HttpServletRequest request){
        System.out.println(request.getRequestURL()+"<--------receiveDataFromX3------url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd");
        boolean f=false;
        System.out.println("获取请求头中传递的数据data开始!!!!!");
        // 得到请求头的name集合
        String data2=null;
        Enumeration<String> em = request.getHeaderNames();
        while (em.hasMoreElements()) {
            String name = em.nextElement();
            if(name.equals("data")){
                data2 = request.getHeader(name);
            }
        }
        System.out.println("获取请求头中传递的数据data结束!!!!!");
        System.out.println(data2+"<---------接收的数据data2");
        if (data2 !=null){
            JSONObject jsonObject = JSON.parseObject(data2);
            JSONArray dataArr = jsonObject.getJSONArray("data");
            if(dataArr.size()>0){
                for (int j = 0; j < dataArr.size(); j++) {
                    String s = dataArr.get(j).toString();
                    JSONObject map = JSON.parseObject(s);
                    String code = map.getString("code2");
                    String value = map.getString("value");
                    String date = map.getString("date");
                    int comment = Integer.parseInt(map.getString("comment"));
                    String note=null;
                    String name2=null;
                    if(comment==1){
                        note="太仓";
                        name2="";
                    }else if (comment==2){
                        note="太仓#7机组";
                        name2="#7";
                    }else if (comment==3){
                        note="太仓#8机组";
                        name2="#8";
                    }
                    String kind1="日报";
                    if(j==0){
                        //删除日报数据
                        boolean b2 = reportFormService.deleTagDataX3(kind1, date);
                        System.out.println(b2+"b2_b2_b2_b2_b2_b2_b2_b2_b2_b2_");
                    }
                    //根据code(神华编码和comment)和kind1查询点的信息
                    PointInfo info=reportFormService.checkInfoByNoteAndCode(code,note,kind1);
                    Date parse=null;
                    try {
                        parse = d2.parse(date);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    TagDataX3 dataX3 = new TagDataX3();
                    dataX3.setComment(1);
                    dataX3.setDatetime(parse);
                    dataX3.setDatetime2(date);
                    dataX3.setKind1(kind1);
                    dataX3.setTagcode(code);
                    if (info !=null){
                        String pointname = info.getPointname();
                        String name3=name2+pointname;
                        dataX3.setKind2(info.getKind2());
                        dataX3.setTagname(name3);
                    }
                    dataX3.setTagname2(note);
                    dataX3.setTagvalue(value);
                    f=reportFormService.addDataFromX3Daily(dataX3);
                }
            }
        }
        if(f){
            resMap.put("data","接收到X3日报数据,并保存成功");
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        }else{
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,传输数据为空或保存数据失败");
        }
        System.out.println(JSON.toJSONString(resMap)+"------日报接收数据接口--------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

    //日报最新数据展示---日报分类页面
    @RequestMapping("/api/showTagNewDataByKind2.do")
    @ResponseBody
    public HashMap<String, Object> showTagNewDataByKind2(HttpServletRequest req){

        System.out.println(req.getRequestURL()+"<----showTagNewDataByKind2----url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            req.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            data=reader.readLine();
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            String kind1 = jsonObject.getString("kind1");
            String kind2 = jsonObject.getString("kind2");
            kind1 = URLDecoder.decode(kind1, "UTF-8");
            kind2 = URLDecoder.decode(kind2, "UTF-8");
            System.out.println(kind1+"<----kind1----kind2--->"+kind2);
            List<TagDataX3> list=new ArrayList<>();
            if(kind1.equals("日报")){
                List<TagDataX3> list2 = reportFormService.showTagNewDataByKind2_NEW(kind1, kind2);
                //List<TagDataX3> list2 = reportFormService.showTagNewDataByKind2_NEW2(kind1, kind2);
                //list=list2;
                if(list2.size()>0){
                    for (TagDataX3 t:list2) {
                        System.out.println(t+"ttttttttttttttttt");
                        if(t!=null){
                            t.setTagvalue(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                            list.add(t);
                        }

                    }
                }
            }
            resMap.put("data",list);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (IOException e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"-------日报最新数据展示接口-------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }

    @RequestMapping("/api/test5.do")
    @ResponseBody
    public HashMap<String, Object> test5(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<----test5----url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        BufferedReader reader = null;
        String data = "";
        try {
            reader = new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            data=reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(data+"data_data_data_data_data_data_");
        JSONObject jsonObject = JSON.parseObject(data);
        String kind1 = jsonObject.getString("kind1");
        String kind2 = jsonObject.getString("kind2");
        System.out.println(kind1+"<----kind1----kind2--->"+kind2);
        List<TagDataX3> list = reportFormService.showTagNewDataByKind2_NEW2(kind1, kind2);
        resMap.put("data",list);
        resMap.put("code","0");
        resMap.put("msg","请求成功");
        System.out.println(JSON.toJSONString(resMap)+"-------日报最新数据展示接口-------");
        System.out.println(new Date()+"<-------------结束时间");
        return resMap;
    }


    //日报曲线展示---------曲线页面
    @RequestMapping("/api/showDailyData.do")
    @ResponseBody
    public HashMap<String, Object> showDailyData(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<------------showDailyData----url");
        System.out.println(new Date()+"<-------------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat d3 = new SimpleDateFormat("yyyy-MM");
        SimpleDateFormat d4 = new SimpleDateFormat("dd");
        String month = d3.format(new Date());
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes());
                data += line;
            }
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject map = JSON.parseObject(data);
            JSONArray codeList = map.getJSONArray("codeList");
            //codeListF数组中放指标的中文意思
            String startDate = map.getString("startDate");
            String endDate = map.getString("endDate");
            System.out.println(startDate+"<-----startDate---"+endDate+"<-----endDate");
            if (startDate==null || startDate.equals("")){
                startDate=month+"-01";
            }
            if (endDate==null || endDate.equals("")){
                endDate=getYesterday();
            }
            Integer st=0;
            Integer en=0;
            Integer num3=0;
            try {
                Date parse2 = d2.parse(startDate);
                Date parse3 = d2.parse(endDate);
                st=Integer.parseInt(d4.format(parse2));
                en=Integer.parseInt(d4.format(parse3));
                num3 = Integer.parseInt(d4.format(new Date()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            List<String> dateList = getDate(st, en);
            System.out.println(startDate+"---startDate---"+endDate+"----endDate---"+codeList+"---------codList---");
            List<Object> list3 = new ArrayList<>();
            if (codeList.size()>0){
                for (int i = 0; i < codeList.size(); i++) {
                    String name = codeList.get(i).toString();
                    List<TagDataX3> list=reportFormService.showDailyDataByName(endDate,startDate,name);
                    System.out.println(JSON.toJSONString(list)+"<==============");
                    Map map2 = new HashMap<>();
                    List<String> list2 = new ArrayList<>();//放指标的数据列表
                    String code2=null;
                    int num=0;
                    for (int a = 0; a < list.size(); a++) {
                        TagDataX3 t=list.get(a);
                        if (code2==null){
                            code2=t.getTagcode();
                        }
                        System.out.println(JSON.toJSONString(list2)+"<--"+t.getDatetime2()+"-----list2--"+a+"---"+num);
                        if (num !=0){
                            num+=1;
                        }
                        for (int j =num; j < dateList.size(); j++) {
                            if (dateList.get(j).equals(t.getDatetime2())){
                                list2.add(j,String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                                num=j;
                                break;
                            }
                            list2.add("0.00");
                        }
                        if ((a+1)==list.size()){
                            Date e_date = d2.parse(t.getDatetime2());
                            Integer s2=Integer.parseInt(d4.format(e_date));
                            System.out.println(s2+"s2_s2_s2_s2_");
                            for (int m = s2+1; m <en; m++) {
                                list2.add("0.00");
                            }
                        }
                    }
                    map2.put("tagName",name);
                    map2.put("tagCode",code2);
                    map2.put("tagValue",list2);
                    list3.add(map2);
                }
            }
            resMap.put("data",list3);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"---日报曲线展示接口----");
        System.out.println(new Date()+"<-------------开始时间");
        return resMap;
    }

//月报
    //接收月报数据---并保存
    @RequestMapping("/api/addDataFromX3ByMonth.do")
    @ResponseBody
    public HashMap<String, Object> receiveMonthDataFromX3(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<--------receiveMonthDataFromX3-----url");
        System.out.println(new Date()+"<-------开始时间");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM");
        HashMap<String, Object> resMap = new HashMap<>();
        boolean f=false;
        String data3=null;
        System.out.println("获取请求头中的数据开始!!!!");
        Enumeration<String> em = req.getHeaderNames();
        while (em.hasMoreElements()){
            String name = em.nextElement();
            if (name.equals("data")){
                data3 = req.getHeader(name);
            }
        }
        System.out.println("获取请求头中的数据结束!!!");
        System.out.println("接收到的数据:"+data3);;
        if (data3 !=null){
            JSONObject jsonObject = JSON.parseObject(data3);
            JSONArray dataArr = jsonObject.getJSONArray("data");
            if(dataArr.size()>0){
                for (int j = 0; j < dataArr.size(); j++) {
                    String s = dataArr.get(j).toString();
                    JSONObject map = JSON.parseObject(s);
                    String code = map.getString("code");
                    String value = map.getString("value");
                    String month = map.getString("month");
                    int comment = Integer.parseInt(map.getString("comment"));
                    String note=null;
                    String name2=null;
                    if(comment==1){
                        note="太仓";
                        name2="";
                    }else if(comment==2){
                        String s7="";
                        note="太仓#7机组";
                        name2="#7";
                    }else if (comment==3){
                        note="太仓#8机组";
                        name2="#8";
                    }
                    String kind1="月报";
                    if(j==0){
                        //删除月报数据
                        boolean b2 = reportFormService.deleTagDataX3(kind1, month);
                        System.out.println(b2+"b2_b2_b2_b2_b2_b2_b2_b2_b2_b2_");
                    }
                    //根据code(神华编码和comment)和kind1查询点的信息
                    PointInfo info=reportFormService.checkInfoByNoteAndCode(code,note,kind1);
                    Date parse=null;
                    try {
                        parse = d2.parse(month);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    TagDataX3 dataX3 = new TagDataX3();
                    dataX3.setComment(1);
                    dataX3.setDatetime(parse);
                    dataX3.setDatetime2(month);
                    dataX3.setKind1(kind1);
                    dataX3.setTagcode(code);
                    if (info !=null){
                        System.out.println("b");
                        String pointname = info.getPointname();
                        String name3=name2+pointname;
                        dataX3.setKind2(info.getKind2());
                        dataX3.setTagname(name3);
                    }
                    dataX3.setTagname2(note);
                    dataX3.setTagvalue(value);
                    System.out.println(dataX3.toString()+"<-------"+j);
                    f=reportFormService.addDataFromX3Daily(dataX3);
                    if (f){
                        System.out.println("添加月报数据成功!!!----->"+code);
                    }else{
                        System.out.println("添加月报数据失败!!!----->"+code);
                    }
                }
            }
        }
        if(f){
            resMap.put("data","接收到月报数据,并保存成功");
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        }else{
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,传输数据为空或保存数据失败");
        }
        System.out.println(JSON.toJSONString(resMap)+"-----接收月报数据接口-------");
        System.out.println(new Date()+"<-------结束时间");
        return resMap;
    }

    //展示月报最新数据
    @RequestMapping("/api/showNewDataByMonth.do")
    @ResponseBody
    public HashMap<String, Object> showPreMonthData(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<----showPreMonthData----url");
        System.out.println(new Date()+"<-------开始时间");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            data=reader.readLine();
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            String kind1 = jsonObject.getString("kind1");
            String kind2 = jsonObject.getString("kind2");
            System.out.println(kind1+"----------"+kind2+"<-------------");
            List<TagDataX3> list=new ArrayList<>();
            if(kind1.equals("月报")){
                List<TagDataX3> list2 = reportFormService.showTagNewDataByMonth_New(kind1, kind2);
                if(list2.size()>0){
                    for (TagDataX3 t:list2) {
                        if(t !=null){
                            t.setTagvalue(String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                            list.add(t);
                        }

                    }
                }
            }
            resMap.put("data",list);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (IOException e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"------月报最新数据展示接口-------");
        System.out.println(new Date()+"<-------结束时间");
        return resMap;
    }

    //曲线展示------月报数据--跨年份的问题没有解决,没有其他问题了
    @RequestMapping("/api/showMonthData.do")
    @ResponseBody
    public HashMap<String, Object> showMonthData(HttpServletRequest req){
        System.out.println(new Date()+"<-------开始时间");
        System.out.println(req.getRequestURL()+"<------------showMonthData----url");
        HashMap<String, Object> resMap = new HashMap<>();
        SimpleDateFormat d3 = new SimpleDateFormat("yyyy");
        String year = d3.format(new Date());
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = "";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes());
                data += line;
            }
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject map = JSON.parseObject(data);
            JSONArray codeList = map.getJSONArray("codeList");   //codeListF数组中放指标的中文意思
            String startTime =year+"-01";
            String endTime = year+"-12";
            List<String> monthList = new ArrayList<>();
            for (int i =1; i <13; i++) {
                String s2=null;
                if (i<10){
                    s2=year+"-0"+i;
                }else{
                    s2=year+"-"+i;
                }
                monthList.add(s2);
            }
            String kind1="月报";
            List<Object> list3 = new ArrayList<>();
            if (codeList.size()>0){
                for (int i = 0; i < codeList.size(); i++) {
                    String name = codeList.get(i).toString();
                    List<TagDataX3> list=reportFormService.showMonthDataByName(startTime,endTime,name,kind1);
                    Map map2 = new HashMap<>();
                    List<String> list2 = new ArrayList<>();//放指标的数据列表
                    String code2=null;
                    int num=0;
                    for (int a = 0; a < list.size(); a++) {
                        TagDataX3 t=list.get(a);
                        if (code2==null){
                            code2=t.getTagcode();
                        }
                        System.out.println(JSON.toJSONString(list2)+"<-------list2");
                        if (num !=0){
                            num+=1;
                        }
                        for (int j =num; j < monthList.size(); j++) {
                            if (monthList.get(j).equals(t.getDatetime2())){
                                list2.add(j,String.format("%.2f",Double.parseDouble(t.getTagvalue())));
                                num=j;
                                break;
                            }
                            list2.add("0.00");
                        }
                        if((a+1)==list.size()&&num !=12){
                            for (int b = num+1; b <12; b++) {
                                list2.add("0.00");
                            }
                        }
                    }
                    map2.put("tagName",name);
                    map2.put("tagCode",code2);
                    map2.put("tagValue",list2);
                    list3.add(map2);
                }
            }
            resMap.put("data",list3);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (IOException e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(JSON.toJSONString(resMap)+"---月报曲线展示接口-----------");
        System.out.println(new Date()+"<-------结束时间");
        return resMap;
    }

    //获取日期列表
    public static   List<String> getDate(Integer start, Integer end){
        SimpleDateFormat d3 = new SimpleDateFormat("yyyy-MM");
        String month = d3.format(new Date());
        System.out.println(month+"_month_month_");
        List<String> list = new ArrayList<>();
        for (int j = start; j <(end+1); j++) {
            String date6=null;
            if (end<10){
                date6=month+"-0"+j;
            }else if (start>=10){
                date6=month+"-"+j;
            }else if (start<10&&end>=10){
                if (j<10){
                    date6=month+"-0"+j;
                }else {
                    date6=month+"-"+j;
                }
            }
            list.add(date6);
        }
        System.out.println(JSON.toJSONString(list));
        return list;
    }
    //获取昨天的日期
    public static String getYesterday(){
        SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        Calendar instance = Calendar.getInstance();
        instance.setTime(date1);
        instance.add(Calendar.DATE,-1);
        String format = d.format(instance.getTime());
        System.out.println(format+"<----------昨天");
        return format;
    }
    //测试的接口-3-------------查询所有User
    @RequestMapping("/api/findAllUsers.do")
    @ResponseBody
    public  HashMap<String, Object> findAllUsers(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<---------url");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            List<User> userList = reportFormService.findAllUsers();
            resMap.put("data",userList);
            resMap.put("code","0");
            resMap.put("msg","请求成功");
        } catch (Exception e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println("接口返回的json:"+JSON.toJSONString(resMap));
        return resMap;
    }

    //自主设定排序功能
    @RequestMapping("/api/saveOrder.do")
    @ResponseBody
    public HashMap<String, Object> saveOrder(HttpServletRequest req){
        System.out.println(new Date()+"<-------开始时间");
        System.out.println(req.getRequestURL()+"<------------saveOrder----url");
        HashMap<String, Object> resMap = new HashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data ="";
            String line;
            while ((line = reader.readLine()) != null) {
                line = new String(line.getBytes());
                data += line;
            }
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject map = JSON.parseObject(data);
            JSONArray codeList = map.getJSONArray("codeList");   //codeList:[{code,name,note,order}]
            String kind1 = map.getString("kind1");
            String kind2 = map.getString("kind2");
            boolean s_b=false;
            if (codeList.size()>0){
                for (int i = 0; i < codeList.size(); i++) {
                    String s = codeList.get(i).toString();
                    JSONObject map2 = JSON.parseObject(s);
                    String note = map2.getString("note");
                    String code = map2.getString("code");
                    String name = map2.getString("name");
                    int order = Integer.parseInt(map2.getString("order"));
                    PointOrder order2 = new PointOrder();
                    order2.setComment(1);
                    order2.setKind1(kind1);
                    order2.setKind2(kind2);
                    order2.setOrder(order);
                    order2.setNote(note);
                    order2.setPointcode(code);
                    order2.setPointname(name);
                    s_b=reportFormService.updateOrAddOrderData(order2);
                    if (s_b){
                        System.out.println("修改或者添加order成功!!!");
                    }else{
                        System.out.println(order2.toString());
                        System.out.println("修改或添加order失败!!!");
                    }
                }
            }
            if (s_b){
                resMap.put("data","顺序设定成功!");
                resMap.put("code","0");
                resMap.put("msg","请求成功");
            }else{
                resMap.put("data","顺序设定失败!");
                resMap.put("code","0");
                resMap.put("msg","请求成功");
            }
        } catch (IOException e) {
            resMap.put("data","");
            resMap.put("code","1");
            resMap.put("msg","请求失败,系统异常");
            e.printStackTrace();
        }
        System.out.println(new Date()+"<-------结束时间");
        return resMap;
    }






//测试用接口-----添加数据
    //批量添加点-------------测试------pointinfo表格
    @RequestMapping("/api/addPointList.do")
    @ResponseBody
    public int addPointList(HttpServletRequest req){
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = reader.readLine();
            //String data = IOUtils.toString(req.getInputStream());
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if(jsonArray.size()>0){
                for (Object p:jsonArray) {
                    Map map=JSON.parseObject(p.toString(),Map.class);
                    String name=map.get("name").toString();
                    String code = map.get("code").toString();
                    String kind1=map.get("kind1").toString();//副分类
                    String kind2 = map.get("kind2").toString().replaceAll(" ","");//主要分类
                    String unit=map.get("unit").toString();//单位
                    String note = map.get("note").toString();//注释
                    String name2=name+"/"+unit;
                    PointInfo p2 = new PointInfo();
                    p2.setPointcode(code);
                    p2.setPointname(name2);
                    p2.setComment(1);
                    p2.setKind1(kind1);
                    p2.setKind2(kind2);
                    p2.setNote(note);
                    p2.setUnit(unit);
                    Boolean b = reportFormService.addPoints(p2);
                    if (b){
                        System.out.println("添加成功!!!<---code------,"+name);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    //添加  月报分类的测试数据------------无问题
    @RequestMapping("/api/addTestData.do")
    @ResponseBody
    public int addTestData(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<----addTestData----url");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM");
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = reader.readLine();
            //String data = IOUtils.toString(req.getInputStream());
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray dataArr = jsonObject.getJSONArray("data");
            if(dataArr.size()>0){
                for (int j = 0; j < dataArr.size(); j++) {
                    String s = dataArr.get(j).toString();
                    JSONObject map = JSON.parseObject(s);
                    String code = map.getString("code2");
                    String value = map.getString("value");
                    String date = map.getString("month");
                    date="2018-"+date;
                    int comment = Integer.parseInt(map.getString("comment"));
                    String note=null;
                    String name2=null;
                    if(comment==1){
                        note="太仓";
                        name2="";
                    }else if (comment==2){
                        note="太仓#7机组";
                        name2="#7";
                    }else if (comment==3){
                        String a1="";
                        note="太仓#8机组";
                        name2="#8";
                    }
                    String kind1="月报";
                    PointInfo info=reportFormService.checkInfoByNoteAndCode(code,note,kind1);
                    Date parse = d2.parse(date);
                    TagDataX3 dataX3 = new TagDataX3();
                    dataX3.setComment(1);
                    dataX3.setDatetime(parse);
                    dataX3.setDatetime2(date);
                    dataX3.setKind1(kind1);
                    dataX3.setTagcode(code);
                    if (info !=null){
                        dataX3.setKind2(info.getKind2());
                        dataX3.setTagname((name2+info.getPointname()));
                    }
                    dataX3.setTagname2(note);
                    dataX3.setTagvalue(value);
                    System.out.println(dataX3.toString()+"<-----TagDataX3");
                    boolean b = reportFormService.addDataFromX3Daily(dataX3);
                    if (b){
                        System.out.println("添加数据成功!!!"+j);
                    }else{
                        System.out.println("添加数据失败!!!"+j);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    //批量添加数据进入TagDataX3表格--------------添加日报分类的测试数据
    @RequestMapping("/api/addTagDataX3Data.do")
    @ResponseBody
    public int addData5(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<----addData5----url");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd");
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = reader.readLine();
            //String data = IOUtils.toString(req.getInputStream());
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray dataArr = jsonObject.getJSONArray("data");
            if(dataArr.size()>0){
                for (int j = 0; j < dataArr.size(); j++) {
                    String s = dataArr.get(j).toString();
                    JSONObject map = JSON.parseObject(s);
                    String code = map.getString("code2");
                    String value = map.getString("value");
                    String date = map.getString("date");
                    int comment = Integer.parseInt(map.getString("comment"));
                    String note=null;
                    String name2=null;
                    if(comment==1){
                        note="太仓";
                        name2="";
                    }else if (comment==2){
                        System.out.println("a");
                        note="太仓#7机组";
                        name2="#7";
                    }else if (comment==3){
                        note="太仓#8机组";
                        name2="#8";
                    }
                    String kind1="日报";
                    PointInfo info=reportFormService.checkInfoByNoteAndCode(code,note,kind1);
                    Date parse= d2.parse(date);
                    TagDataX3 dataX3 = new TagDataX3();
                    dataX3.setComment(1);
                    dataX3.setDatetime(parse);
                    dataX3.setDatetime2(date);
                    dataX3.setKind1(kind1);
                    dataX3.setTagcode(code);
                    if (info !=null){
                        dataX3.setKind2(info.getKind2());
                        dataX3.setTagname((name2+info.getPointname()));
                    }
                    dataX3.setTagname2(note);
                    dataX3.setTagvalue(value);
                    System.out.println(dataX3.toString()+"<-----TagDataX3");
                    boolean b = reportFormService.addDataFromX3Daily(dataX3);
                    if (b){
                        System.out.println("添加数据成功!!!"+j);
                    }else{
                        System.out.println("添加数据失败!!!"+j);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    //添加测试数据----------tagInfo
    @RequestMapping("/api/addTagData.do")
    @ResponseBody
    public void addTagData(HttpServletRequest req){
        System.out.println(req.getRequestURL()+"<---------------url");
        SimpleDateFormat d2 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat d3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTime = d2.format(new Date());
        String collTime = d3.format(new Date());
        try {
            BufferedReader reader =new BufferedReader(new InputStreamReader(req.getInputStream(),"utf-8"));
            String data = reader.readLine();
            //String data = IOUtils.toString(req.getInputStream());
            System.out.println(data+"data_data_data_data_data_data_");
            JSONObject jsonObject = JSON.parseObject(data);
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            if (jsonArray.size()>0){
                boolean f= reportFormService.updateStatus();
                for (int i = 0; i < jsonArray.size(); i++) {
                    String s = jsonArray.get(i).toString();
                    System.out.println(s+"<------------"+i);
                    JSONObject map = JSON.parseObject(s);
                    String tagValue = map.get("tagVlue").toString();
                    String tagCode = map.get("tagName").toString();
                    String tagName2 = map.get("tagName2").toString();
                    TagInfo tagInfo = new TagInfo();
                    tagInfo.setTagname(tagCode);
                    tagInfo.setColltime(collTime);
                    tagInfo.setComment(1);
                    tagInfo.setDatetime(dateTime);
                    tagInfo.setTagvalue(tagValue);
                    tagInfo.setTagname2(tagName2);
                    tagInfo.setStatus("new");
                    System.out.println(tagInfo.toString());
                    if (f){
                        boolean b = reportFormService.addData(tagInfo);
                        if (b){
                            System.out.println("添加成功!!!"+"<------"+i+"<----"+tagCode);
                        }else{
                            System.out.println("添加失败!!!"+"<------"+i+"<----"+tagCode);
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
